package cn.ljy.uem.config;

import cn.ljy.uem.web.interceptor.backstage.SchoolTeacherInterceptor;
import cn.ljy.uem.web.interceptor.frontend.mobile.LoginForSchoolStudentInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.LinkedList;

/**
 * 拦截器配置
 */
@Configuration
public class SchoolWebConfigurer implements WebMvcConfigurer {

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //学生登录验证的拦截器
       registry.addInterceptor(loginForSchoolStudentInterceptor())
            .addPathPatterns("/api/mobile/schoolstudent/**")//要拦截的路径
            //.addPathPatterns("/api/shop/order/**")//要拦截的路径
            .excludePathPatterns(new LinkedList<String>(){{//不拦截的路径（一般指addPathPatterns中包含，但是不进行拦截的特例）
                add("/api/mobile/schoolstudent/login");
                add("/api/mobile/schoolstudent/logout");
            }});
       //教师拦截
        registry.addInterceptor(schoolTeacherInterceptor())
                .addPathPatterns("/api/backstage/school/schoolTeacherCourse/**");//要拦截的路径
                //.addPathPatterns("/api/shop/order/**")//要拦截的路径
//                .excludePathPatterns(new LinkedList<String>(){{//不拦截的路径（一般指addPathPatterns中包含，但是不进行拦截的特例）
//                    add("/api/mobile/schoolstudent/login");
//                    add("/api/mobile/schoolstudent/logout");
//                }});
    }

    //创建拦截器对象，只有通过这里才能让拦截器中的依赖注入生效
    //前台学生登陆拦截器
    @Bean
    public LoginForSchoolStudentInterceptor loginForSchoolStudentInterceptor() {
        return new LoginForSchoolStudentInterceptor();
    }

    //后台教师身份拦截器
    @Bean
    public SchoolTeacherInterceptor schoolTeacherInterceptor() {
        return new SchoolTeacherInterceptor();
    }

}
